<template>
  <div class="select-temple-view">
    <div class="temple-view-box1">
      <div class="box1-1">已配置大屏</div>
      <div class="box1-2">
        <div
          v-for="(item, index) in hasconfigList"
          :key="index"
          class="base-box"
          @mouseenter="setidone(item.id)"
        >
          <div v-if="nowhasconfigid === item.id" class="selected-main">
            <div class="selected-main-line1">{{ item.templename }}</div>
            <div class="selected-main-line2">
              <div class="selected-main-line2-but" @click="showscreenview()">查看大屏</div>
              <div class="selected-main-line2-but" @click="delscreenview(item.id)">删除大屏</div>
            </div>
          </div>
          <div v-else class="base-box-title">{{ item.templename }}</div>
        </div>
      </div>
    </div>
    <div class="temple-view-box2">
      <div class="box2-1">选择模板</div>
      <div class="box2-2">
        <div
          v-for="(item, index) in hastempleList"
          :key="index"
          class="base-box"
          @mouseenter="setid(item.templateId)"
        >
          <div v-if="nowhastempleid === item.templateId" class="selected-main">
            <div class="selected-main-line1">{{ item.templateName }}</div>
            <div class="selected-main-line2">
              <div class="selected-main-line2-but" @click="showtempleview()">预览模板</div>
              <div class="selected-main-line2-but" @click="toaddScreen(item)">创建大屏</div>
            </div>
          </div>
          <div v-else class="base-box-title">{{ item.templateName }}</div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import axios from 'axios';
export default {
  data() {
    return {
      // 基地id-必须值
      baseid: "",
      // 已配置大屏
      hasconfigList: [
        // { templename: "旧馆高质量粮油示范基地大屏一", id: 1 },
        // { templename: "旧馆高质量粮油示范基地大屏二", id: 2 },
        // { templename: "旧馆高质量粮油示范基地大屏三", id: 3 },
        // { templename: "旧馆高质量粮油示范基地大屏三", id: 4 },
        // { templename: "旧馆高质量粮油示范基地大屏三", id: 5 },
        // { templename: "旧馆高质量粮油示范基地大屏四", id: 6 }
      ],
      nowhasconfigid: "",
      // 已拥有模板
      hastempleList: [
        // { templateName: "旧馆高质量粮油示范基地大屏一", templateId: 1 },
        // { templateName: "旧馆高质量粮油示范基地大屏二", templateId: 2 }
      ],
      nowhastempleid: "",
      organizationMark: ""
    };
  },
  mounted() {
    this.goback();
  },
  methods: {
    // 展示已配置大屏
    showscreenview() {
      this.$message.success("链接跳转查看！")
    },
    delscreenview(id) {
      let baseurl = this.$zhurl
      let requrl = baseurl + '/cockpit/delCockpit'
      let params = {
        cockpitId: id
      }
      axios({
        method: "POST",
        url: requrl,
        data: params
      }).then(response => {
        let mes = response.data.code
        if (mes && mes === 1) {
          this.$message.success("删除成功！")
          this.getallscreenlist()
        }
      })
    },
    // 获取所有已配置大屏
    getallscreenlist() {
      this.hasconfigList = []
      let baseurl = this.$zhurl
      let requrl = baseurl + '/cockpit/queryInfo'
      axios({
        method: "GET",
        url: requrl,
        timeout: 10000,
        headers: {
          "organizationMark": this.organizationMark
        }
      }).then(response => {
        let mes = response.data.data
        if (mes) {
          let newlist = {
            id: mes.cockpitId,
            templename: mes.cockpitName
          }
          console.log(mes)
          this.hasconfigList.push(newlist)
        } else {
          this.$message.error("已配置大屏查询失败或无数据！")
        }
      })
    },
    // 获取所有模板
    getalltemlist() {
      let baseurl = this.$zhurl
      let requrl = baseurl + '/template/queryTemplateList'
      axios({
        method: "GET",
        url: requrl
      }).then(response => {
        let mes = response.data.data
        if (mes) {
          this.hastempleList = mes
        }
      })
    },
    // 预览模板
    showtempleview() {
      this.$message.success("链接跳转查看！")
    },
    // 跳转新建大屏-须带模板id
    toaddScreen(e) {
      if (e) {
        this.$store.dispatch("tagsView/delView", this.$route).then(() => {
          this.$message.success("选择模板成功");
          setTimeout(() => {
            this.$router.push({ name: "addScreen", query:
            {
              'organizationMark': this.organizationMark, ...e }
            });
          }, 1000);
        });
      } else {
        this.$message.warning("这e有毒丫丫");
      }
    },
    setidone(id) {
      this.nowhasconfigid = id;
    },
    setid(id) {
      this.nowhastempleid = id;
    },
    // 判断是否返回上一步选择基地
    goback() {
      let query = this.$route.query;
      if (query.id && query.id > 0) {
        this.baseid = query.id;
        this.organizationMark = query.organizationMark
        this.getalltemlist();
        this.getallscreenlist();
      } else {
        this.$nextTick(() => {
          this.$store.dispatch("tagsView/delView", this.$route).then(() => {
            this.$message.warning("无基地参数id");
            setTimeout(() => {
              this.$router.push({ name: "selctBase" });
            }, 1000);
          });
        });
      }
    }
  }
};
</script>

<style lang="scss" scoped>
.select-temple-view {
  width: 100%;
  height: 100%;
  .temple-view-box1 {
    width: 100%;
    height: 250px;
    margin-top: 15px;
    .box1-1 {
      width: 115px;
      margin-left: 15px;
      height: 30px;
      line-height: 30px;
      letter-spacing: 3px;
      white-space: nowrap;
      font-size: 20px;
      background-color: #022b35;
      position: relative;
      z-index: 5;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #ffffff;
    }
    .box1-2 {
      width: calc(100% - 30px);
      height: 220px;
      margin-left: 15px;
      margin-top: -15px;
      border-top: 2px dashed #01444e;
      padding: 15px 0;
      position: relative;
      z-index: 4;
      display: flex;
      flex-wrap: wrap;
      overflow-y: auto;
      justify-content: space-around;
      .base-box {
        width: 296px;
        height: 200px;
        margin-right: 2px;
        margin-bottom: 10px;
        cursor: pointer;
        background-image: url("../../../assets/index-bgc.png");
        background-size: cover;
        position: relative;
        border: #009fa5 1px solid;
        .base-box-title {
          width: 296px;
          height: 30px;
          line-height: 30px;
          text-align: center;
          position: absolute;
          bottom: 0;
          left: 0;
          background-color: rgba(23, 24, 24, 0.2);
          letter-spacing: 3px;
          white-space: nowrap;
        }
        .selected-main {
          width: 300px;
          height: 200px;
          position: absolute;
          top: 0;
          left: 0;
          background-color: rgba(23, 24, 24, 0.6);
          background-size: cover;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          border: #009fa5 1px solid;
          .selected-main-line1 {
            width: 300px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            letter-spacing: 3px;
            white-space: nowrap;
            font-size: 15px;
          }
          .selected-main-line2 {
            width: 300px;
            height: 25px;
            margin-top: 10px;
            display: flex;
            justify-content: center;
            .selected-main-line2-but {
              width: 100px;
              height: 25px;
              line-height: 25px;
              text-align: center;
              background: rgb(32, 22, 22);
              border-radius: 5px;
              color: #00d5cd;
              border: 1px solid #00d5cd;
              font-size: 14px;
              letter-spacing: 2px;
            }
            .selected-main-line2-but:hover {
              background: #00d5cd;
              color: rgb(32, 22, 22);
            }
            .selected-main-line2-but:first-of-type {
              margin-right: 10px;
            }
          }
        }
      }
    }
  }
  .temple-view-box2 {
    width: 100%;
    .box2-1 {
      width: 115px;
      margin-left: 15px;
      height: 30px;
      line-height: 30px;
      letter-spacing: 3px;
      white-space: nowrap;
      font-size: 20px;
      background-color: #022b35;
      position: relative;
      z-index: 5;
      font-family: PingFang SC-Regular, PingFang SC;
      font-weight: 400;
      color: #ffffff;
    }
    .box2-2 {
      width: calc(100% - 30px);
      height: calc(100% - 40px);
      margin-left: 15px;
      margin-top: -15px;
      border-top: 2px dashed #01444e;
      padding: 15px 0;
      position: relative;
      z-index: 4;
      display: flex;
      flex-wrap: wrap;
      overflow-y: auto;
      justify-content: space-around;
      .base-box {
        width: 300px;
        height: 200px;
        margin-right: 2px;
        margin-bottom: 10px;
        cursor: pointer;
        background-image: url("../../../assets/index-bgc.png");
        background-size: cover;
        position: relative;
        border: #009fa5 1px solid;
        .base-box-title {
          width: 300px;
          height: 30px;
          line-height: 30px;
          text-align: center;
          position: absolute;
          bottom: 0;
          left: 0;
          background-color: rgba(23, 24, 24, 0.2);
          letter-spacing: 3px;
          white-space: nowrap;
        }
        .selected-main {
          width: 300px;
          height: 200px;
          position: absolute;
          top: 0;
          left: 0;
          background-color: rgba(23, 24, 24, 0.6);
          background-size: cover;
          display: flex;
          flex-direction: column;
          justify-content: center;
          align-items: center;
          border: #009fa5 1px solid;
          .selected-main-line1 {
            width: 300px;
            height: 30px;
            line-height: 30px;
            text-align: center;
            letter-spacing: 3px;
            white-space: nowrap;
            font-size: 15px;
          }
          .selected-main-line2 {
            width: 300px;
            height: 25px;
            margin-top: 10px;
            display: flex;
            justify-content: center;
            .selected-main-line2-but {
              width: 100px;
              height: 25px;
              line-height: 25px;
              text-align: center;
              background: rgb(32, 22, 22);
              border-radius: 5px;
              color: #00d5cd;
              border: 1px solid #00d5cd;
              font-size: 14px;
              letter-spacing: 2px;
            }
            .selected-main-line2-but:hover {
              background: #00d5cd;
              color: rgb(32, 22, 22);
            }
            .selected-main-line2-but:first-of-type {
              margin-right: 10px;
            }
          }
        }
      }
    }
  }
}
</style>
